package com.example.simple.myapplication;

import android.app.FragmentTransaction;
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    public static final String EXTRA_MESSAGE = "com.example.simple.myapplication.MESSAGE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar = findViewById(R.id.my_toolbar);
        System.out.println("before toolbar:" + toolbar);
        toolbar.setLogoDescription("电视");
        toolbar.setLogo(R.drawable.ic_live_tv_black_18dp);
//        toolbar.setNavigationIcon(R.drawable.ic_search);
        toolbar.setSubtitle("你好");
        toolbar.setTitleTextColor(getResources().getColor(R.color.d));
        toolbar.setSubtitleTextColor(0xFFFF0000);
        toolbar.setAlpha(1f);
        toolbar.setBackgroundColor(getResources().getColor(R.color.b));
//        Toolbar.LayoutParams tl = new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT);
//        tl.setMarginStart(3);
        TextView tv = new TextView(this);
        tv.setText("Tab1");
        tv.setTextColor(0xFFFF0000);
        toolbar.addView(tv);

        TextView tv2 = new TextView(this);
        tv2.setText("Tab2");
        tv2.setTextColor(0xFF000000);
        toolbar.addView(tv2);

        setSupportActionBar(toolbar);

//        ActionBar ab = getSupportActionBar();
//        System.out.println("after toolbar:" + ab);
//        ab.setDisplayShowHomeEnabled(true);
//        ab.setDisplayShowTitleEnabled(true);
//        ab.setLogo(R.drawable.ic_live_tv_black_18dp);
//        ab.setDisplayUseLogoEnabled(true);
//        ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

//        Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
//        setSupportActionBar(myToolbar);

//        for (int i = 0;i < 4;i++) {
//            ActionBar.Tab tab = ab.newTab();
//            tab.setText("Tab" + i);
//            tab.setTabListener(tabListener);
//            ab.addTab(tab);
//        }
    }

    public void toast(View view) {
        Toast.makeText(MainActivity.this, "你好", Toast.LENGTH_SHORT);
    }

    private ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        @Override
        public void onTabSelected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {
            Toast.makeText(MainActivity.this, tab.getText(), Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onTabUnselected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {

        }

        @Override
        public void onTabReselected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {

        }
    };

    public void sendMessage(View view){
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        TextView textView = findViewById(R.id.editText);
        String message = textView.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.activity_main_actions, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        TextView tv =  findViewById(R.id.editText);
        switch (item.getItemId()) {
            case R.id.action_search:
                tv.setText("点击了搜索");
                return true;
            case R.id.action_settings:
                tv.setText("点击了设置");
                return true;
            case 110:
                tv.setText("红色");
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}
